import { Token } from '@/types/data.d.';
import dayjs from 'dayjs';

const key = 'GEEK-TOKEN'
const setToken = (token: Token): void => {
  // console.log(token)
  localStorage.setItem(key, JSON.stringify(token))
}
const getToken = () => {
  return JSON.parse(localStorage.getItem(key) ?? '{}') as Token
}
const removeToken = (): void => {
  localStorage.removeItem(key)
}
// 判断是否已经登录 是否有token (鉴权) 场景：可以判断一个值是否为空 !! 可以将值转变为对应的 boolean 值
const isToken = (): boolean => !!getToken().token

// 格式化时间
const formatTime = (time: Date | string, type: string = 'YYYY-MM-DD') => {
  return dayjs(time).format(type)
}
export { setToken, getToken, removeToken, isToken, formatTime };


